package com.softcloud.comingforyuan.model;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.softcloud.comingforyuan.R;

import java.util.List;

/**
 * Created by 喆歆 on 2015/7/5.
 */
public class ExerciseAdapter extends ArrayAdapter<Exercise>{

    private int resourceId;

    public ExerciseAdapter(Context context, int resource, List<Exercise> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Exercise currExercise = getItem(position);
        View view;
        ViewHolder  viewHolder;
        if(convertView == null){
            view = LayoutInflater.from(getContext()).inflate(resourceId,null);
            viewHolder = new ViewHolder();
            viewHolder.questionText = (TextView)view.findViewById(R.id.adapter_question);
            viewHolder.yourAnswerContentText = (TextView)view.findViewById(R.id.adapter_your_answer);
            viewHolder.rightAnswerContentText = (TextView)view.findViewById(R.id.adapter_right_answer);
            viewHolder.analysesText = (TextView)view.findViewById(R.id.adapter_analyses);
            view.setTag(viewHolder);
        }else {
            view = convertView;
            viewHolder = (ViewHolder)view.getTag();
        }
        viewHolder.questionText.setText(currExercise.getQuestion());
        viewHolder.yourAnswerContentText.setText(currExercise.getCurrAnswerContent());
        viewHolder.rightAnswerContentText.setText(currExercise.getRightAnswerContent());
        viewHolder.analysesText.setText(currExercise.getAnalyses());
        return view;
    }

    class ViewHolder{
        TextView questionText;
        TextView yourAnswerContentText;
        TextView rightAnswerContentText;
        TextView analysesText;
    }
}
